import React, { Component, PureComponent } from 'react'

// 使用ref获取子组件的实例，子组件必须是类组件
// 函数式组件没有实例
// class Child extends PureComponent {
//   state = { title: '标题' }
//   render () {
//     console.log('child')
//     return (
//       <div>child</div>
//     )
//   }
// }

const Child = () => {
  const fn = () => {
    console.log('fn')
  }
  return (
    <div>child</div>
  )
}
export default class App extends Component {
  childRef = React.createRef()
  render() {
    return (
      <div>
        <button onClick = { () => {
          console.log(this.childRef.current)
        }}>获取子组件的数据</button>
        <Child ref = { this.childRef }/>
      </div>
    )
  }
}
